package com.stormrage.edu.dao.edu.view.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.edu.impl.EduProjectDaoImpl;
import com.stormrage.edu.dao.edu.view.EduProjectMajorDao;
import com.stormrage.entity.edu.view.EduProjectMajor;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @author www.stormragetech.com
 * @date 2016年1月19日
 * @version 1.0.0
 */
@Repository
public class EduProjectMajorDaoImpl extends MysBaseDao implements EduProjectMajorDao {

	private static final Logger logger = LoggerFactory.getLogger(EduProjectDaoImpl.class);

	@Override
	public Integer create(final EduProjectMajor arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 Create 】- 开始运行 ");

		final String query = "INSERT INTO edu_project_major (project_id, major_id) VALUES (:projectId, :majorId)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 Create 】- 完成运行 ");
		return index;
	}

	@Override
	public void deleteById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 DeleteById 】- 开始运行 ");

		final String query = "DELETE FROM edu_project_major WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 DeleteById 】- 完成运行 ");

	}

	@Override
	public void deleteByProjectId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 DeleteByProjectId 】- 开始运行 ");

		final String query = "DELETE FROM edu_project_major WHERE project_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 DeleteByProjectId 】- 完成运行 ");

	}

	@Override
	public void deleteByMajorId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 DeleteByMajorId 】- 开始运行 ");

		final String query = "DELETE FROM edu_project_major WHERE major_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 DeleteByMajorId 】- 完成运行 ");

	}

	@Override
	public Integer queryCountById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 queryCountById 】- 开始运行 ");

		final String query = "SELECT COUNT(*) FROM edu_project_major WHERE project_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】- 【 EduProJectMajorDao 】- 【 queryCountById 】- 完成运行 ");
		return count;
	}

}
